package com.jieshao

import com.jieshao.utils.LineShareBundle
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.*

class I18nTest {
    @Test
    fun test(){
        Locale.getDefault().language.equals("zh").let {
            //properties默认ISO_8859_1读取,但是实测UTF8,IDEA也支持,并且在编辑器中更友好识别，idea使用jdk11 bundle可以识别utf8,@see java.util.PropertyResourceBundle.PropertyResourceBundle(java.io.InputStream)
            with(System.getProperty("java.version")){
                when{
                    //1.8之前,觉得很少人用1.9、1.10就一起算进去了
                    startsWith("1.",true)->assertEquals("代码行分享",LineShareBundle.message("action.LineShare.name").toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8))
                    //其他
                    else->assertEquals("代码行分享",LineShareBundle.message("action.LineShare.name"))
                }
            }

        }
    }

    @Test
    fun i18nTest(){
        with(System.getProperty("java.version")) {
            when {
                //仅对11以后进行测试
                !startsWith("1.", true) -> {
                    assertEquals("代码行分享", ResourceBundle.getBundle("messages.LineShareBundle",Locale.CHINESE, ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES)).getString("action.LineShare.name"))
                    assertEquals("line share", ResourceBundle.getBundle("messages.LineShareBundle",Locale.ENGLISH, ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES)).getString("action.LineShare.name"))
                }
                else-> println("jdk版本太低")
            }
        }
    }
}